<script type="text/javascript">
    
    function sendRequestViaMultiFriendSelector() {
        
        FB.ui({method: 'apprequests',            
            message: 'Jeg deltar i Primusshop.no sin konkurranse om å vinne en gourmetlunsj for meg og 5 av mine venner, under High Camp på Hemsedal 9.-11. mars 2012.',
            max_recipients: 5,
            title: 'Hjelp meg å vinne en gourmetlunsj'
            
        }, requestCallback);
        
    }
    
    
    function requestCallback(response) {
        var l = response.to.length;
        for(i=0;i<l;i++) {
            FB.api("/" + response.to[i],function(data){
                var d = document.getElementById("answer_text2");
                var t = document.getElementById("tagfriends");
                if(d.value == "") {
                    d.value += data.name;
                    t.value += "@[" + data.id + ":1:" + data.name + "]";
                } else {
                    d.value += ", " + data.name;
                    t.value += ", " + "@[" + data.id + ":1:" + data.name + "]";
                }                
            });
        }
    }
</script>
<div class="home_body">
    <center>          
    <?php if ($view->isLogined) { ?>
        <br/>
        <?php if ($view->isCommented) { ?>        
        <p align="left" style="font-size:14pt;font-weight: bold;">Ditt bidrag er registrert</p>
        <?php } ?>
        <form method="post" id="submit-answer-form" style="text-align: left;width: 90%;">
            <input type="hidden" name="data[tagfriends]" id="tagfriends" />
            <table width="100%" border="0">
                <tr>
                    <td valign="top" style="vertical-align: top;">
                        <p style="line-height: 21px;">Jeg skal vinne en gourmetlunsj fordi: </p>
                        <textarea <?php if ($view->isCommented) { ?> disabled="disabled" readonly="readonly" <?php } ?> style="width: 470px;" name="data[answer_text1]" cols="30" rows="5"><?php echo str_replace("\\'", "'", nl2br($view->commentData['answer_text1'])); ?></textarea>     
                        
                        <p style="line-height: 21px;">Jeg ønsker å invitere følgende fem venner: </p>
                        <textarea id="answer_text2" <?php if ($view->isCommented) { ?> disabled="disabled" readonly="readonly" <?php } ?> style="width: 350px;" name="data[answer_text2]" cols="30" rows="5"><?php echo str_replace("\\'", "'", nl2br($view->commentData['answer_text2'])); ?></textarea>     
                        <?php if (!$view->isCommented) { ?>
                        <input type="button" value="Select friends" style="float: right;margin-right: 14px;" onclick="sendRequestViaMultiFriendSelector();"/>
                        <br/><br/>
                        
                        <a href="javascript:jQuery('#submit-answer-form').submit();">
                            <img src="layouts/images/send_btn.png" alt="Send" />
                        </a>
                        <?php } ?>
                    </td>
                    <td width="172">
                        <p style="line-height: 21px;">Hei <a target="_blank" href="http://www.facebook.com/profile.php?id=<?php echo $view->user['facebook_user_id']; ?>"><?php echo $view->user['name']; ?></a></p>                        
                        <?php if ($view->isCommented) { ?>
                        <div style="border-color: #C5CFDB;border-style: solid;border-width: 1px 0;margin-bottom: 8px;margin-top: 8px;">
                            <p style="line-height: 21px;">Øk dine vinnersjanser ved å oppfordre venner og bekjente til å stemme på ditt bidrag. Bruk Knappene under for å dele på Facebook.</p>
                            <p style="line-height: 21px;">
                                <a href="javascript:facebooktab.share();"><img src="images/facebook_button.png" style="width: 60px;" /></a>

                            <?php 
                                $likeURL = $view->config['lightbox_like_url'] . "&data_id=" . $view->commentData['data_id'];                    
                            ?>

                            <iframe src="//www.facebook.com/plugins/like.php?href=<?php echo urlencode($likeURL); ?>&amp;send=false&amp;layout=button_count&amp;width=90&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=20" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:90px; height:20px;" allowTransparency="true"></iframe>
                            </p>
                        </div>
                        <?php } ?>
                        <a target="_blank" href="http://www.facebook.com/profile.php?id=<?php echo $view->user['facebook_user_id']; ?>">
                            <img style="border-width: 0px; width: 172px;" src="<?php echo $view->user['facebook_user_picture']; ?>" /></a>                        
                        <p style="line-height: 21px;">Antall stemmer: <b><?php echo ($view->commentData['total_like'] == "") ? "0" : $view->commentData['total_like']; ?></b> </p>                        
                    </td>
                </tr>
            </table>            
        </form>      
        
    <?php } else { ?>   
        <?php 
        echo str_replace("[connect_to_facebook]", '<a href="javascript:contestapp.loginFacebook();"><img style="vertical-align: middle;" src="layouts/images/connec-to-fb.png" alt="Connect to facebook" /></a>', $view->contest['signup_tab_text']);
        ?>        
            <br/>   
            <br/>   
    <?php } ?>
    </center>
</div>
<script type="text/javascript">
    // set up share data
    facebooktab.setFacebookShareData({
        picture:'http://ssl.socialmediatoolbox.no/contest/exist/images/logo.png',
        name:'Hjelp meg å vinne en gourmetlunsj',
        caption:'Stem på mitt bidrag slik at jeg kan invitere 5 venner på en gourmetlunsj på High Camp 2012',
        url:'<?php echo $view->config['facebooktab_share_url'] . "&app_data=" . $view->commentData['data_id']; ?>',
        actionText:'PrimusShop.no'
    });
</script>
